<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">
<h:head>

	<style type="text/css">
.ui-layout-north {
	z-index: 20 !important;
	overflow: visible !important;;
}

.ui-layout-north .ui-layout-unit-content {
	overflow: visible !important;
}

.ui-widget {
	font-size: 10px !important;
}

.size {
	width: 550px;
	position: relative;
	left: 30%;
	top: 10%;
}

.centro {
	top: 50%
}

.tabela {
	width: 750px;
}
</style>


	<title>Cadastro de Conta Corrente</title>
</h:head>
<h:body>
	<ui:decorate template="/templateBase.xhtml">
		<ui:define name="center">
			<p:growl id="growl" life="3000" autoUpdate="true" />
			<h:form prependId="false" id="formCadastro">
				<p:outputPanel autoUpdate="true">
					<br />
					<br />
					<br />
					<p:panel header="Cadastrar Conta Corrente" styleClass="size"
						toggleable="true"
						footer="SIGLAS - Sistema de Gerenciamento de Laboratório de Análise de Solo">

						<br />
						<h:panelGrid columns="3">
							<h:outputText value="Banco:" />
							<p:inputText maxlength="50" size="50" id="txtBanco"
								required="true" requiredMessage="Selecione o banco"
								value="#{contaCorrenteBacking.banco.nome}" />
							<p:commandButton value="F2" icon="ui-icon-search"
								oncomplete="dlgBanco.show()" immediate="true"
								action="#{contaCorrenteBacking.carregaBanco}" />
						</h:panelGrid>
						<h:panelGrid columns="3">
							<h:outputText value="Agência:" />
							<p:inputMask maxlength="5" size="7" mask="?99999" required="true"
								requiredMessage="Número agência"
								value="#{contaCorrenteBacking.contaCorrenteSalvar.agencia}" />
							<p:inputMask maxlength="1" size="1" mask="?9"
								value="#{contaCorrenteBacking.contaCorrenteSalvar.digitoAgencia}" />

							<h:outputText value="Conta Corrente:" />
							<p:inputMask maxlength="5" size="7" required="true"
								requiredMessage="Número conta"
								value="#{contaCorrenteBacking.contaCorrenteSalvar.contaCorrente}" />
							<p:inputMask maxlength="1" size="1" mask="9" required="true"
								requiredMessage="Dígito conta"
								value="#{contaCorrenteBacking.contaCorrenteSalvar.digitoConta}" />

						</h:panelGrid>
						<h:panelGrid columns="2">
							<h:outputText value="Estado:(*)" />
							<p:selectOneMenu effect="drop" id="estado" required="true"
								requiredMessage="Estado inválido"
								value="#{contaCorrenteBacking.estadoSalvar}">
								<f:selectItem itemLabel="Selecione um Estado" />
								<f:selectItems value="#{contaCorrenteBacking.listaEstados}"
									var="e" itemValue="#{e.codigo}"
									itemLabel="#{e.nome} - #{e.sigla}" />
								<p:ajax event="change"
									listener="#{contaCorrenteBacking.carregarCidades}" />
							</p:selectOneMenu>

							<h:outputText value="Cidade:(*)" />
							<p:selectOneMenu effect="drop" id="cidade" required="true"
								requiredMessage="Estado inválido"
								value="#{contaCorrenteBacking.cidadeSalvar}">
								<f:selectItem itemLabel="Selecione uma Cidade" />
								<f:selectItems value="#{contaCorrenteBacking.listaCidades}"
									var="c" itemLabel="#{c.nome}" itemValue="#{c.codigo}" />

							</p:selectOneMenu>
						</h:panelGrid>

						<h:panelGrid columns="2">
							<p:commandButton value="Salvar" icon="ui-icon-disk" ajax="false"
								actionListener="#{contaCorrenteBacking.salvar}" />
							<p:commandButton value="Cancelar" icon="ui-icon-cancel"
								action="#{contaCorrenteBacking.reset}" ajax="false"
								immediate="true" />
						</h:panelGrid>

					</p:panel>


					<p:dialog id="pesquisaBanco" widgetVar="dlgBanco"
						header="Pesquisar Bancos" closable="true" resizable="false"
						showEffect="clip" hideEffect="clip">

						<p:dataTable id="tabelaBanco" var="ban" rowKey="#{ban.codigo}"
							value="#{contaCorrenteBacking.listaBanco}" paginator="true"
							rows="10" selectionMode="single"
							selection="#{contaCorrenteBacking.banco}">

							<p:ajax event="rowSelect" oncomplete="dlgBanco.wide()"
								global="false" immediate="true" />
							<p:ajax event="rowUnselect" update=":formCadastro" />

							<f:facet name="header">
								<h:outputText value="Bancos Cadastrados" />
							</f:facet>

							<p:column headerText="Código">
								<h:outputText value="#{ban.codigoFormatado}" />
							</p:column>

							<p:column headerText="Descrição" filterBy="#{ban.nome}">
								<h:outputText value="#{ban.nome}" />
							</p:column>

							<p:column headerText="Sigla" filterBy="#{ban.sigla}">
								<h:outputText value="#{ban.sigla}" />
							</p:column>

							<p:column headerText="Código Bancário" filterBy="#{ban.codigo}">
								<h:outputText value="#{ban.getCodigoBancario()}" />
							</p:column>

							<p:column headerText="Ação">
								<p:commandButton value="Selecionar" oncomplete="dlgBanco.wide()"
									process="@this" immediate="true" ajax="false"
									update=":formCadastro:txtBanco">
									<f:setPropertyActionListener
										target="#{contaCorrenteBacking.banco}" value="#{ban}" />
								</p:commandButton>
							</p:column>

						</p:dataTable>
					</p:dialog>
				</p:outputPanel>
			</h:form>
			<h:form prependId="false" id="formPesquisa">
				<p:dialog id="pesquisaConta" widgetVar="dlgConta"
					header="Pesquisar Contas" closable="true" height="400" width="400"
					resizable="false" showEffect="clip" hideEffect="clip">
					<p:dataTable var="p"
						value="#{contaCorrenteBacking.listaContaCorrente}" rows="10"
						widgetVar="con" paginator="true" id="tabelaConta"
						emptyMessage="Nenhum registro foi encontrado, tente novamente!">
						<h:outputText value="Proprietarios Cadastrados" />

						<p:column filterBy="#{con.codigo}" headerText="Nome">
							<h:outputText value="#{con.codigoFormatado}" />
						</p:column>

						<p:column filterBy="#{con.banco.nome}" headerText="Banco">
							<h:outputText value="#{con.banco.nome}" />
						</p:column>

						<p:column filterBy="#{con.agencia}" headerText="Agência">
							<h:outputText value="#{con.agencia}-#{con.agencia.digitoAgencia}" />
						</p:column>

						<p:column filterBy="#{con.contaCorrente}" headerText="Número CC">
							<h:outputText value="#{con.contaCorrente}-#{con.digitoConta}" />
						</p:column>

						<p:column headerText="Ações">
							<div align="center">
								<h:panelGrid columns="2" border="-1">
									<p:commandButton icon="ui-icon-pencil"
										oncomplete="dlgBanco.hide()" update=":formCadastro">
										<f:setPropertyActionListener
											target="#{contaCorrenteBacking.contaCorrenteSelecionada}"
											value="#{con}" />
									</p:commandButton>
									<p:commandButton icon="ui-icon-close"
										oncomplete="dlgDelete.show()">
										<f:setPropertyActionListener
											target="#{contaCorrenteBacking.contaCorrenteSelecionada}"
											value="#{con}" />
									</p:commandButton>


								</h:panelGrid>
							</div>
						</p:column>
					</p:dataTable>
				</p:dialog>


				<p:dialog id="confirmaDelete" widgetVar="dlgDelete"
					header="Deletar Registro" closable="true" width="230"
					resizable="false" showEffect="clip" hideEffect="clip">
					<div align="center">
						<h:outputText value="Deseja realmente excluir esse registro?" />
						<h:panelGrid columns="2">
							<p:commandButton value="Sim" onsuccess="dlgDelete.hide()"
								actionListener="#{contaCorrenteBacking.delete}"
								update=":formCadastro:pesquisaBanco, :formCadastro"
								process="@all" immediate="true" />
							<p:commandButton value="Não" onclick="dlgDelete.hide()" />
						</h:panelGrid>
					</div>
				</p:dialog>
			</h:form>

		</ui:define>
	</ui:decorate>
</h:body>
</html>
